R/f - Is same.R

Defines functions f_is_same

Documented in f_is_same

#' @title Are values in two vectors/columns the same.
#'
#' @description Check per index/row whether values in two vectors/columns are the same.
#'
#' @author Pieter Overdevest
#'
#' @param x1 Column or vector 1.
#' @param x2 Column or vector 2.
#'
#' @return Column containing TRUE or FALSE.
#'
#' @details -
#'
#' @examples
#' f_is_same(
#'        x1 = c(1,2,3,4,5,NA),
#'        x2 = c(1,2,3,4,NA,NA)
#' )
#'
#' @export
#'
#################################################################################
# FUNCTION.
#################################################################################

        f_is_same <- function(

                x1, x2
        ) {


##############################################################################
# TEST ONLY!!
##############################################################################

##############################################################################
# Initialize // Error checking
##############################################################################

##############################################################################
# Main
##############################################################################

        v.output <- ifelse(

                !is.na(x1) & !is.na(x2),

                {x1 == x2},

                ifelse(
                        is.na(x1) & is.na(x2),
                        TRUE,
                        FALSE
                )
        )

##############################################################################
# Return
##############################################################################

        return(v.output)

        }
pieterov/generaltoolbox documentation built on Jan. 25, 2025, 10:32 a.m.